<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/8/11
  Time: 15:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/checkstu.css" />
</head>

<body>
<form action="CheckStuByIdOrNoServlet" method="post">
<div id="top">
    <div id="topLeft">
        根据学号查找
        <input type="text" name="stu_no"  value="" />
        <button type="submit">查找</button>
    </div>
    <div id="topRight">
        根据姓名查找
        <input type="text" name="stu_name" value="" />
        <a href="#"><button type="submit" >查找</button></a>
    </div>
</div>
</form>
<div id="middle">
    <form action="${pageContext.request.contextPath}/DeleteBatchStuServlet" method="post" name="delform">
        <table class="dataintable">
            <tr>
                <td><input type="checkbox" name="allChecks"  onclick="allCheck(this.checked)">全选</td>
                <td>学号</td>
                <td>姓名</td>
                <td>性别</td>
                <td>系别</td>
                <td>班级</td>
                <td>联系方式</td>
                <td>楼号</td>
                <td>宿舍号</td>
                <td>学生会</td>
                <td>操作</td>
                <td>任免学生会</td>
            </tr>
            <c:forEach var="stu" items="${sessionScope.item}">
            <tr>
                <td >

                    <input type="checkbox" name="stuBox"  value="${stu.stu_id}" />
                </td>
                <td>${stu.stu_no}</td>
                <td>${stu.stu_name}</td>
                <td>${stu.stu_sex}</td>
                <td>${stu.d_name}</td>
                <td>${stu.c_name}</td>
                <td>${stu.stu_tel}</td>
                <td>${stu.dor_build}</td>
                <td>${stu.dor_no}</td>
                <td>${stu.stu_statis}</td>
                <td>
                    <button type="button" onclick="deleteStu('${stu.stu_id}')">删除</button>
                    <button type="submit" formaction="${pageContext.request.contextPath}/CheckStuToUpdateStuServlet?stu_id=${stu.stu_id}">修改</button>
                </td>
                <td>
                    <button type="submit" formaction="${pageContext.request.contextPath}/AppointStuServlet?stu_id=${stu.stu_id}&stu_statis=1">任命</button>
                    <button type="submit" formaction="${pageContext.request.contextPath}/AppointStuServlet?stu_id=${stu.stu_id}&stu_statis=0">罢免</button>
                </td>
            </tr>
            </c:forEach>
        </table>
        <button type="button" onclick="allDelete()">批量删除</button>
        <button type="button" onclick="allAppr()">批量任命</button>
        <button type="button" onclick="allUnAppr()">批量罢免</button>
    </form>
</div>
<div id="foot">
    <div >

        <c:if test="${sessionScope.pageIndex==1}">
            首页
            上一页
        </c:if>
        <c:if test="${sessionScope.pageIndex>1}">
            <a href="${pageContext.request.contextPath}/LeftToCheckStuServlet?pageIndex=1">首页</a>
            <a href="${pageContext.request.contextPath}/LeftToCheckStuServlet?pageIndex=${sessionScope.pageIndex-1}">上一页</a>
        </c:if>
        <lib>${sessionScope.pageIndex}/${sessionScope.pageNum}</lib>
        <c:if test="${sessionScope.pageIndex<sessionScope.pageNum}">
            <a href="${pageContext.request.contextPath}/LeftToCheckStuServlet?pageIndex=${sessionScope.pageIndex+1}">下一页</a>
            <a href="${pageContext.request.contextPath}/LeftToCheckStuServlet?pageIndex=${sessionScope.pageNum}">尾页</a>
        </c:if>
        <c:if test="${sessionScope.pageIndex==sessionScope.pageNum}">
            下一页
            尾页
        </c:if>
         </div>
</div>
</div>
</body>
<script type="text/javascript">

    var check=document.getElementsByName("stuBox");
    function allCheck(f){
        for (var i = 0; i < check.length; i++) {
            check[i].checked=f;
        }
    }
    function deleteStu(n){
        var f=confirm("是否要删除?!");
        if (f){
            location.href="${pageContext.request.contextPath}/DeleteStuServlet?stu_id="+n;
        }
    }
    function allDelete() {
        var b=false;
          for(var i=0;i<check.length;i++){
              if(check[i].checked==true){
                  b=true;
                  break;
              }
          }
         if (b){
            var t=confirm("是否批量删除?!");
            if(t){
                document.delform.submit();
            }
        } else{
            alert("请选择要删除的学生!");
        }
    }
    function allAppr() {
        var c=false;
        for(var i=0;i<check.length;i++){
            if(check[i].checked==true){
                c=true;
                break;
            }
        }
        if(c){
            document.delform.action="${pageContext.request.contextPath}/AppiontBatchStuServlet?stu_statis=1";
            document.delform.submit();
        }else{
            alter("请选择要任命的学生!");
        }

    }
    function allUnAppr() {
        var d=false;
        for(var i=0;i<check.length;i++){
            if(check[i].checked==true){
                d=true;
                break;
            }
        }
        if(d==true){
            document.delform.action="${pageContext.request.contextPath}/AppiontBatchStuServlet?stu_statis=0";
            document.delform.submit();
        }else{
            alter("请选择要罢免的学生!");
        }
    }
</script>
</html>